package com.me.libgdx_test;

import java.util.ArrayList;
import java.util.Arrays;

public class ClassPlayerSpellMod {
	//Modifiers for what happens when spells are used/destroyed
	//Spell Cost Modifiers: teleport 6 mana, +2 cost all spells, manaspark half mana, endwall 1 mana, -1 all spells
	//Spell Hit Modifiers: teleported enemy poisoned, summons special shops from affinity, 10% dmg returned as mana
	//Spell Cast Modifiers: +1 gold endwall, grumpkins level 2, totems add +2 health/mana as well, heals 1.5 per mana used,
	//  Spells use 8% max health down to 1 health, 2 health per lvl for wall destruction
	//Spell Destroy Modifier: raises upper bounds of attack range by 20%, 5% death gaze chance, 5% life steal
	//Spell prohibited: attack spells
	float spell_strength;
	String spell_with_cost_changed;
	int cost;
	String spell_destroy_modifiers; 
	String spell_hit_modifiers;
	String spells_prohibited;
	String starting_spell;
	ArrayList<String> spell_cast_modifiers;
	int mana_spark_divisor;
	float spell_destruction_bonus;
	ClassPlayerSpellMod(float spell_strength, String spell_with_cost_changed, int cost, String starting_spell, String spell_destroy_modifiers, 
			String spell_hit_modifiers, String spells_prohibited, String...spell_cast_modifiers){
		this.spell_strength = spell_strength;
		this.spell_with_cost_changed = spell_with_cost_changed;
		this.cost = cost;
		this.spell_destroy_modifiers = spell_destroy_modifiers;
		//this.spell_cast_modifiers = spell_cast_modifiers;
		this.spell_hit_modifiers = spell_hit_modifiers;
		this.spells_prohibited = spells_prohibited;
		this.starting_spell = starting_spell;
		this.spell_cast_modifiers = new ArrayList<String>(Arrays.asList(spell_cast_modifiers));
		spell_destruction_bonus = 1;
		//this.spell_cast_modifiers = new String[spell_cast_modifiers.length];
		//System.arraycopy( spell_cast_modifiers, 0, this.spell_cast_modifiers, 0, spell_cast_modifiers.length );
		mana_spark_divisor = 2;
	}
	public void add_starting_spell(ClassCharacterPlayer player, ClassDungeonSpell[] spells){
		//ClassLogDisplay logger = new ClassLogDisplay("ClassPlayerSpellMod");
		//logger.print("Looking: " + starting_spell);
		for(ClassDungeonSpell spell:spells){
			//logger.print(spell.Name);
			if(spell.Name.equals(starting_spell)){
				//logger.print("Found: " + starting_spell);
				for(int i = 0; i < player.get_spells().length;i++){
					if(player.get_spells()[i].get_spell_info() == null){
						player.get_spells()[i] = new ClassObjectSpellDungeon(spell);
						break;
					}
				}
			}
		}
	}
	public boolean can_cast_spell(ClassObjectSpellDungeon spell){
		boolean can_cast = true;
		if (spells_prohibited.equals("attack") && spell.get_spell_info().attack_spell){
			can_cast = false;
		}
		return can_cast;
	}
	//Spell Cast Modifiers: +1 gold endwall, grumpkins level 2, totems add +2 health/mana as well, heals 1.5 per mana used,
	//  Spells use 8% max health down to 1 health, 2 health per lvl for wall destruction
	public void pre_cast_modifiers(ClassCharacterPlayer player, ClassObjectSpellDungeon spell){
		for(String cast_mod: spell_cast_modifiers){
			if(cast_mod.equals("totem_upgrade") && spell.get_spell_info().Name.equals("Totem")){
				spell.upgrade_totem();
			}
			if(cast_mod.equals("grumpkin_upgrade") && spell.get_spell_info().Name.equals("Grumpkin")){
				spell.upgrade_grumpkin();
			}
			if(cast_mod.equals("mana_spark_cheap")){
				mana_spark_divisor = 4;
			}
		}
	}
	public void post_cast_modifiers(ClassCharacterPlayer player, ClassObjectSpellDungeon spell){
		
		player.add_god_action("used_magic");
		if(spell.get_spell_info().status_benefit){
			player.add_god_action("benefits");
		}
		
		if(spell.get_spell_info().Name == "EndWall"){
			player.add_god_action("destroyed_walls");
		}
		
		if(spell.get_spell_info().Name == "Petrify"){
			player.add_god_action("made_walls");
		}
		
		for(String cast_mod: spell_cast_modifiers){
			if(cast_mod.equals("benefit_spells_poison") && spell.get_spell_info().status_benefit){
				player.set_contracted_mod("Poison", true);
			}
			if(cast_mod.equals("1_gold_endwall") && spell.get_spell_info().Name.equals("EndWall")){
				player.set_player_variable("gold",player.get_player_variable("gold")+1);
			}
			if(cast_mod.equals("+1_hp_endwall") && spell.get_spell_info().Name.equals("EndWall")){
				player.set_player_variable("max_health",player.get_player_variable("max_health")+1);
			}
			if(cast_mod.equals("+2_hp_endwall") && spell.get_spell_info().Name.equals("EndWall")){
				player.set_player_variable("max_health",player.get_player_variable("max_health")+2);
			}
			if(cast_mod.equals("+3_hp_endwall") && spell.get_spell_info().Name.equals("EndWall")){
				player.set_player_variable("max_health",player.get_player_variable("max_health")+3);
			}
			if(cast_mod.equals("+5_hp_endwall") && spell.get_spell_info().Name.equals("EndWall")){
				player.set_player_variable("max_health",player.get_player_variable("max_health")+5);
			}
			if(cast_mod.equals("spells_8%_health")){
				player.set_player_variable("current_health",player.get_player_variable("current_health") - (int)(player.get_max_health()*.08));
				if(player.get_player_variable("current_health")<1){
					player.set_player_variable("current_health",1);
				}
			}
			if(cast_mod.equals("3/2_mana_used")){
				player.set_player_variable("current_health",(int)(player.get_player_variable("current_health") + spell.get_spell_info().cost * 1.5));
			}
			if(cast_mod.equals("2_health_lvl_endwall")){
				player.set_player_variable("current_health",player.get_player_variable("current_health") + player.get_player_variable("level") * 2);
			}
		}
	}
	public void hit_modifier(ClassCharacterPlayer player, ClassObjectSpellDungeon spell, ClassCursorAt cursor,int dmg){
		/*
		 * 	ClassCursorAt(Point location,ClassCharacterEnemy enemy){this.location.move(location);this.enemy = enemy; cursor_object_type=1;}
	ClassCursorAt(Point location,ClassObjectShopDungeon shop){this.location.move(location);this.shop = shop; cursor_object_type=2;}
	ClassCursorAt(Point location,ClassObjectPickupDungeon pickup){this.location.move(location);this.pickup = pickup; cursor_object_type=3;}
	ClassCursorAt(Point location,ClassObjectTotem totem){this.location.move(location);this.totem = totem; cursor_object_type=4;}
	ClassCursorAt(Point location,ClassObjectSpellDungeon spell){this.location.move(location);this.spell = spell; cursor_object_type=5;}
		 */
		if(spell_hit_modifiers.equals("teleport_poison") 
				&& cursor.get_object_type() == 1 
				&& spell.get_spell_info().Name.equals("Teleport")){
			cursor.enemy.set_contracted_mod("Poison", true);
		}
		if(spell_hit_modifiers.equals("affinity_shops") 
				&& cursor.get_object_type() == 3 
				&& cursor.pickup.get_pickup_info().get_item_type() == 8 
				&& spell.get_spell_info().Name.equals("Affinity")){
			//Put affinity shop code here
		}
		if(spell_hit_modifiers.equals("10%_dmg_mana") 
				&& spell.get_spell_info().attack_spell){
			int additional_mana = (int) (dmg*.1>1?dmg*.1:1);
			player.set_player_variable("current_mana", player.get_player_variable("current_mana")+additional_mana);
		}
	}
	public void destroy_glyph(ClassCharacterPlayer player){
		if(spell_destroy_modifiers.equals("upper_bound")){
			player.upper_bounds += .2;
		}
		if(spell_destroy_modifiers.equals("5%_gaze")){
			player.set_player_variable_float("death_gaze", player.get_player_variable_float("death_gaze")+.05f);
		}
		if(spell_destroy_modifiers.equals("5%_life_steal")){
			player.set_player_variable_float("life_steal", player.get_player_variable_float("life_steal")+.05f);
		}
	}
	public int get_cost(ClassObjectSpellDungeon spell){
		if(spell_with_cost_changed.equals("all")){
			return spell.get_spell_info().cost + this.cost;
		}
		if(spell_with_cost_changed.equals(spell.get_spell_info().Name)){
			return spell.get_spell_info().cost = this.cost;
		}
		return spell.get_spell_info().cost;
	}

}
